local lock = require "resty.lock"
local GlobalModule={}

local locksObjects={}

function GlobalModule:get(key)
	local lockobj=lock:new('objects')
	local elapsed, err=lockobj:lock(key)
	if not elapsed then
		return elapsed, err
	end
	local ret=locksObjects[key]
	local ok, err=lockobj:unlock()
	if not ok then
		return ok, err
	end
	return ret
end

function GlobalModule:set(key,obj)
	local lockobj=lock:new('objects')
	local elapsed, err=lockobj:lock(key)
	if not elapsed then
		return elapsed, err
	end
	locksObjects[key]=obj
	local ok, err=lockobj:unlock()
	if not ok then
		return ok, err
	end
	return true
end

return GlobalModule